package com.example.common;

import com.example.common.enums.ResultCodeEnum;

/**
 * 统一响应结果类
 */
public class Result {
    
    private String code;
    private String msg;
    private Object data;

    public Result() {
    }

    public Result(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 成功响应（无数据）
     */
    public static Result success() {
        return new Result(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg, null);
    }

    /**
     * 成功响应（带数据）
     */
    public static Result success(Object data) {
        return new Result(ResultCodeEnum.SUCCESS.code, ResultCodeEnum.SUCCESS.msg, data);
    }

    /**
     * 失败响应（系统错误）
     */
    public static Result error() {
        return new Result(ResultCodeEnum.SYSTEM_ERROR.code, ResultCodeEnum.SYSTEM_ERROR.msg, null);
    }

    /**
     * 失败响应（自定义错误码和消息）
     */
    public static Result error(String code, String msg) {
        return new Result(code, msg, null);
    }

    /**
     * 失败响应（使用枚举）
     */
    public static Result error(ResultCodeEnum resultCodeEnum) {
        return new Result(resultCodeEnum.code, resultCodeEnum.msg, null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
